package test

import java.io.File

import org.apache.commons.io.FileUtils
import utils.ExecCommand

object getCpData {


  def main(args: Array[String]): Unit = {


    getJbCmd

  }

  def getCpPepAndCds = {
    val p = "D:\\藻类细胞器\\cpgb3"

    new File(p).listFiles().foreach{x=>

      val command = "perl D:/藻类细胞器/藻类细胞器数据库构建/genbank_parser_v4.0.pl --type all " + x.getAbsolutePath + ""

      val exec = new ExecCommand()
      exec.exect(Array(command),   "D:\\藻类细胞器\\cpgb3" )

    }
  }

  def getJbDir = {
    val path ="D:\\藻类细胞器\\cpjb/"
    new File(path).listFiles().filter(_.getName.contains("gb")).foreach{x=>
      val name = x.getName.split("gb").head.init

      if(!new File(path+name).exists()){
        new File(path+name).mkdir()
      }

      FileUtils.moveFile(x,new File(path+name+"/" + x.getName))

    }
  }

  def reGetJbDir = {
    val path ="D:\\藻类细胞器\\cpjb/"
    new File(path).listFiles().foreach { x =>

      try{

        val name = x.getName.split('.').head

        FileUtils.moveDirectory(x,new File(path + name))
      }catch {
        case e =>
          println(x.getName)
      }

    }
  }

  def getJbCmd = {

    new File("D:\\藻类细胞器/getCpJB.sh").delete()
    val path = "/mnt/sdb/xwq/Jbrowser/apache-tomcat-9.0.0.M11/webapps/jb/my_data/PODB/CP/"

    new File("D:\\藻类细胞器\\cpjb").listFiles().foreach { x =>


      val n = x.getName
      val sh = s"cd /mnt/sdb/xwq/Jbrowser/apache-tomcat-9.0.0.M11/webapps/jb/my_data/PODB/CP/$n;\n"+
        s"../../../../bin/prepare-refseqs.pl -fasta ./*.gb.seq;\n"+
        s"../../../../bin/prepare-refseqs.pl --conf data/trackList.json;\n"+
        s"../../../../bin/flatfile-to-json.pl --gff ./*.gb.gff --trackType FeatureTrack --trackLabel Annotation;\n"+
        s"../../../../bin/biodb-to-json.pl --conf data/trackList.json ;\n"

      FileUtils.writeStringToFile(new File("D:\\藻类细胞器/getCpJB.sh"),sh,true)
    }
  }



}
